import http from '@/utils/request.ts'

export const index = {
  /**
   * 上传文件
   * @param file 文件
   * @param directory 上传目录（可选，默认为default）
   */
  uploadFile: async (file: File, directory?: string): Promise<any> => {
    const formData = new FormData()
    formData.append('file', file)
    if (directory) {
      formData.append('directory', directory)
    }

    const response = await http.post<any>('/file/upload', formData, {
      timeout: 30000
    })
    return response.data
  }
}